package org.chengn.level_middle.context2336;

import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;

public class Context2336 {
    static class SmallestInfiniteSet{
        private int val = 1;
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        Set<Integer> set = new HashSet<>();
        public SmallestInfiniteSet() {

        }

        public int popSmallest() {
            Integer peek = queue.peek();
            if (peek == null || val <= peek) {
                return val++;
            }
            set.remove(peek);
            return queue.poll();
        }

        public void addBack(int num) {
            if (val <= num || set.contains(num)) return;
            queue.add(num);
            set.add(num);
        }
    }
}
